package com.ocom.accesservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.accesservice.dao.PersonnelInfoDao;
import com.ocom.accesservice.service.MjYkmVoService;
import com.ocom.accesservice.vo.PersonnelYkmVo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.utils.StringUtils;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MjYkmVoServiceImpl extends ServiceImpl<PersonnelInfoDao, PersonnelYkmVo> implements MjYkmVoService {

    @Autowired
    private PersonnelInfoDao personnelInfoDao;

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId")
    @Override
    public PersonnelYkmVo selectGetYkmPersonnelSum(Long comId,String deptIds) {
        if (StringUtils.isNotEmpty(deptIds)){
            List<Integer> typeList = new ArrayList<>();
            String[] typeStr = deptIds .split(",");
            for (int i = 0; i < typeStr.length; i++) {
                typeList.add(Integer.valueOf(typeStr[i]));
            }
            return personnelInfoDao.deptIdsList(comId,typeList);
        }else {
            return personnelInfoDao.dyGetUserList(comId);
        }

    }
}
